Description

Interceptors allow you to define code to be executed before and/or after the execution of an action. Interceptors can be a powerful tool when writing web applications. Some of the most common implementations of an Interceptor might be:

  • Security Checking (ensuring the user is logged in)
  • Trace Logging (logging every action)
  • Bottleneck Checking (start a timer before and after every action, to check bottlenecks in your application)
    You can also chain Interceptors together to create an interceptor stack. If you wanted to do a login check, security check, and logging all before an Action call, this could easily be done with an interceptor package.

Intercepters must first be defined (to give name them) and can be chained together as a stack:

<interceptors>
  <interceptor name="security" class="com.mycompany.security.SecurityInterceptor"/>
  <interceptor-stack name="defaultComponentStack">
    <interceptor-ref name="component"/>
    <interceptor-ref name="defaultStack"/>
  </interceptor-stack>
</interceptors>

To use them in your actions:

<action name="VelocityCounter" class="com.opensymphony.webwork.example.counter.SimpleCounter">
   <result name="success">...</result>
   <interceptor-ref name="defaultComponentStack"/>
</action>

NOTE: Reference name can be either the name of the interceptor or the name of a stack

For more details, see Interceptors reference.

Most of the content here provided by Matt Dowell <[email protected]>